﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace RStein.Posterous.API
{
    internal class TagsResponseBuilder : IResultResponseParser<IEnumerable<string>>
    {
        #region Implementation of IResultResponseParser<out IEnumerable<string>>

        public IEnumerable<string> GetResults(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            XmlReader reader = XmlReader.Create(stream);
            XElement root = XElement.Load(reader);
            var tags = (from tag in root.Elements(GlobalConstants.XML_TAG_ELEMENT)
                       select (string) tag.Element(GlobalConstants.XML_TAG_NAME_ELEMENT)).ToList();
            
            return tags;
                                        
        }

        #endregion
    }
}
